package com.example.materialviewpagerdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.materialviewpagerdemo.bean.LeftListModel;
import com.example.materialviewpagerdemo.view.LeftListAdapter;

import java.util.ArrayList;
import java.util.List;

public class DrawerActivity extends AppCompatActivity {
    private DrawerLayout mDrawer;
    private ActionBarDrawerToggle mDrawerToggle;
    private ListView listView;
    List<LeftListModel> leftListModelList=new ArrayList<>();
    @Override
    protected void onStart() {
        super.onStart();
        leftListModelList.clear();
        listView=findViewById(R.id.listview);
        for (int i=0;i<1;i++){
            LeftListModel leftListModel=new LeftListModel();
            leftListModel.setImgId(R.drawable.qrcode);
            leftListModel.setItemContent("分享");
            leftListModelList.add(leftListModel);
        }
        listView.setAdapter(new LeftListAdapter(this,leftListModelList));

        mDrawer = findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
        mDrawer.setDrawerListener(mDrawerToggle);
        setTitle("");
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                DrawerActivity.this.startActivity(new Intent(DrawerActivity.this,QRActivity.class));
                close();
            }
        });
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setHomeButtonEnabled(true);
        }

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return mDrawerToggle.onOptionsItemSelected(item) ||
                super.onOptionsItemSelected(item);
    }
    protected void close(){
        mDrawer.closeDrawers();
    }




}
